<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /*后代选择器*/
        .done li {
            color: green;
            text-decoration: line-through;
        }

        .todo li {
            width: 200px;
            height: 35px;
            position: relative;
        }

        /*.todo li button{
            float: right;
        }*/
        .todo li button {
            /*绝对定位：会以第一个不是默认定位得父元素为原点进行定位*/
            position: absolute;
            top: 0;
            right: 0;
        }
    </style>
</head>

<body>
    <p>vue方法</p>
    <div id="app">
        <p>待办事项</p>
        <!--第一部分，记录-->
        <input type="text" id="inp" placeholder="请输入待办事项">
        <button @click="save()">保存</button>
        <!--第二部分，待办事项-->
        <p>待办事项</p>
        <ol class="todo" id="todo">
            <li v-for="(item, index) in todotihings">
                <span>{{item}}</span>
                <button @click="done(index)">完成</button>
            </li>
        </ol>
        <!--第三部分，已完成事项-->
        <p>已完成事项</p>
        <ol class="done">
            <li v-for="(item, index) in donetihings">
                <span>{{item}}</span>
            </li>
        </ol>
    </div>
    <script src="./vue.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                //事项
                thing: '',
                //待办事项
                todotings: [],
                donethings: []
            },
            methods: {
                save() {
                    if (this.thing)
                        this.todotings.push(this.thing);
                    this.thing = '';
                },
                done(index) {
                    //加入到已完成
                    this.donetings.push(this.todo[index]);
                    //从待办事项中移除
                    this.todotings.splice(index, 1);
                }
            }
        });
    </script>
</body>

</html>